//
//  main.m
//  arrDemo
//
//  Created by zhouxiaobo on 15/10/23.
//  Copyright © 2015年 mapath. All rights reserved.
//

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        NSArray *arr = [[NSArray alloc]initWithObjects:@"one",@"two",@"three", nil];
        NSArray *arr1 = [[NSArray alloc]initWithArray:arr];
        NSArray *arr2 = [[NSArray alloc]initWithArray:arr copyItems:true]; //clone一个新的数组
        
        //获取数据中的第2个
        NSString *s = [arr objectAtIndex:2];
        NSLog(@"第2个是:%@",s);
        
        //迭代器遍历
        NSEnumerator *enumerator = [arr objectEnumerator];
        id obj;
        while (obj = [enumerator nextObject]){
            NSLog(@"%@",obj);
        }
        
        //快速遍历
        for (id obj1 in arr1){
            NSLog(@"%@",obj1);
        }
        
        //遍历
        for (int i=0;i<[arr2 count];i++){
            NSLog(@"%@",[arr2 objectAtIndex:i]);
        }
        
        NSMutableArray *arr3 = [[NSMutableArray alloc]init];
        [arr3 addObject: @"zhou"];
        [arr3 addObject:@"xiao"];
        [arr3 addObject:@"bo"];
        
        NSLog(@"%@",arr3);
        
        [arr3 removeObject:@"zhou"];
        NSLog(@"%@",arr3);
        
        [arr3 removeObjectsInRange:(NSRange){0,1}];
        NSLog(@"%@",arr3);
        
        [arr3 addObject:@"yu"];
        [arr3 addObject:@"li"];
        [arr3 addObject:@"jun"];
        NSLog(@"%@",arr3);
    
        //数组交换位置
        [arr3 exchangeObjectAtIndex:0 withObjectAtIndex:3];
        NSLog(@"%@",arr3);
        
        //数组与字符串的转换
        NSString *str = @"This is zhou xiao bo's book!";
        NSArray *strArr = [str componentsSeparatedByString:@" "]; //以空格分开字符串转成数组
        NSLog(@"%@",strArr);
        
        NSMutableArray *strRevertArr = [[NSMutableArray alloc]init];
        NSEnumerator *revertEnumerator = [strArr reverseObjectEnumerator];  //逆序迭代器
        id obj2 = nil;
        
        while (obj2 = [revertEnumerator nextObject]) {
            [strRevertArr addObject:obj2];
        }
        NSLog(@"%@",strRevertArr);
    }
    return 0;
}
